/*
 * GMMFactory.java
 * Created on Nov 4, 2008
 *
 * Glacéo Internet Platform
 * http://sourceforge.net/projects/chm/
 *
 * Copyright (c) 2005-2009, Jens and Jan Janke (VirtualHockey Project)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hockeo.vhbase.seasoncycle.movemaking;


import java.util.concurrent.Executor;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.hockeo.vhbase.data.dao.club.GClub;
import com.hockeo.vhbase.data.dao.contest.GContestElement;
import com.hockeo.vhbase.data.dao.season.GMoveday;
import com.hockeo.vhbase.data.dao.user.GComputerUser;

/**
 * Class responsible for creating move-making tasks that can be run by using an
 * {@link Executor} via the {@link GMoveMakingService}.
 *
 * @version $Id$
 * @author jjanke
 */
public class GMMFactory implements ApplicationContextAware
{
  private ApplicationContext d_appctx;

  public void setApplicationContext( final ApplicationContext appctx ) throws BeansException
  {
    d_appctx = appctx;
  }

  /**
   * Creates a new MoveMaker callable that is responsible for executing a
   * specific move-making task.
   *
   * @param user the user that is responsible for making the moves
   * @param club the club for which to make the moves
   * @param element the contest element for which to make the moves
   * @param moveday the moveday for which the moves should be computed
   * @param fIsLastMoveday whether this is the last moveday of the season in the contest
   *          element
   * @return the created {@link IGMoveMaker} implementation
   */
  public GMMCallable createMoveMakerCallable( final GComputerUser user, final GClub club,
      final GContestElement element, final GMoveday moveday, final boolean fIsLastMoveday )
  {
    IGMoveMaker moveMaker = (IGMoveMaker) d_appctx.getBean( element.getMoveMakingImplName( user ) );

    moveMaker.setEnvironment( club, element, moveday, fIsLastMoveday );

    return new GMMCallable( moveMaker );
  }
}
